using System.Collections.Generic;
using RollManager.Library.Utils;
using System.Text;

namespace RollManager.Library
{
    partial class Database
    {
        public static List<History> GetHistory( int subActionId )
        {
            return runMapper<History>( "GetHistory", subActionId );
        }

        public static List<HistoryExtended> GetHistoryExtended()
        {
            return runMapper<HistoryExtended>( "GetHistoryExtended" );
        }

        public static void AddHistory( int subActionId, string result, Dictionary<string,string> context )
        {
            if( subActionId > 0 )
            {
                // Create displayable string of context contents
                StringBuilder sb = new StringBuilder();
                foreach( string key in context.Keys )
                {
                    sb.AppendFormat( "{0}={1}, ", key, context[ key ] );
                }
                if( sb.Length > 0 )
                {
                    sb.Remove( sb.Length - 2, 2 );
                }

                runQuery( "AddHistory", subActionId, Common.UserName, result, sb.ToString() );
            }
        }
    }
}
